<!doctype html>
<html class="no-js" ng-app="App" xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Amaze UI Admin form Examples</title>
    <meta name="description" content="这是一个form页面">
    <meta name="keywords" content="form">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="icon" type="image/png" href="/static/assets/i/favicon.png">
    <link rel="apple-touch-icon-precomposed" href="/static/assets/i/app-icon72x72@2x.png">
    <meta name="apple-mobile-web-app-title" content="Amaze UI"/>
    <link rel="stylesheet" href="/static/assets/css/amazeui.min.css"/>
    <link rel="stylesheet" href="/static/assets/css/admin.css">
    <link rel="stylesheet" href="/static/assets/css/jquery-ui.min.css"/>

</head>
<body ng-controller="SurveyCtrl">

<!--[if lte IE 9]>
<p class="browsehappy">你正在使用<strong>过时</strong>的浏览器，Amaze UI 暂不支持。 请 <a href="http://browsehappy.com/" target="_blank">升级浏览器</a>
    以获得更好的体验！</p>
<![endif]-->

<header class="am-topbar admin-header">
    <div class="am-topbar-brand">
        <strong>血脂专家</strong>
        <small>后台管理</small>
    </div>

    <button class="am-topbar-btn am-topbar-toggle am-btn am-btn-sm am-btn-success am-show-sm-only"
            data-am-collapse="{target: '#topbar-collapse'}"><span class="am-sr-only">导航切换</span> <span
            class="am-icon-bars"></span></button>

    <div class="am-collapse am-topbar-collapse" id="topbar-collapse">

        <ul class="am-nav am-nav-pills am-topbar-nav am-topbar-right admin-header-list">
            <li><a href="/survey/admin"><span class="am-icon-users"></span> 退出 </a></li>
            <li><a href="javascript:;" id="admin-fullscreen"><span class="am-icon-arrows-alt"></span> <span
                    class="admin-fullText">开启全屏</span></a></li>
        </ul>
    </div>
</header>

<div class="am-cf admin-main">

    <!-- content start -->
    <div class="admin-content">

        <div class="am-cf am-padding">
            <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">Schedule</strong> /
                <small>form</small>
            </div>
        </div>
        <form class="am-form" name="myForm" ng-submit="save()" ng-model="schedule">

            <div class="am-g am-margin-top">
                <div class="am-u-sm-2 am-text-right">
                    用户手机号
                </div>
                <div class="am-u-sm-10">
                    <label type="text" class="am-input-sm">{{schedule.userPhone}} ({{schedule.userPhoneCreateDate}})</label>
                </div>
            </div>

            <div class="am-g am-margin-top">
                <div class="am-u-sm-2 am-text-right">
                    上一次已经完成问卷
                </div>
                <div class="am-u-sm-10">
                    <label type="text" class="am-input-sm">{{schedule.lastSurvey}}</label>
                </div>
            </div>

            <div class="am-g am-margin-top-sm">
                <div class="am-u-sm-2 am-text-right">
                    当前需要完成问卷
                </div>
                <div class="am-u-sm-10">
                    <label rows="10" ng-model="schedule.currentSurvey"
                           required="不能为空">{{schedule.currentSurvey}}</label>
                </div>
            </div>

            <div class="am-g am-margin-top">
                <div class="am-u-sm-2 am-text-right">
                    下一次需要完成问卷
                </div>
                <div class="am-u-sm-10">
                    <label type="text" class="am-input-sm"
                           ng-model="schedule.nextSurvey">{{schedule.nextSurvey}}</label>
                </div>
            </div>
            <div class="am-g am-margin-top">
                <div class="am-u-sm-2 am-text-right">
                    第一次完成问卷时间
                </div>
                <div class="am-u-sm-10">
                    <!--<p><input type="text" data-date-format="yyyy-mm-dd hh:ii" class="am-form-field"-->
                    <!--data-am-datepicker todayBtn="true"-->
                    <!--ng-model="schedule.firstDone"-->
                    <!--readonly/></p>-->

                    <!--<div class="am-input-group am-datepicker-date" data-am-datepicker="{format: 'dd-mm-yyyy'}">-->
                    <!--<input type="text" class="am-form-field" placeholder="日历组件" ng-value="schedule.firstDone*1000-->
                    <!--| date : 'yyyy-MM-dd HH:mm:ss'" readonly>-->
                    <!--<span class="am-input-group-btn am-datepicker-add-on">-->
                    <!--<button class="am-btn am-btn-default" type="button"><span-->
                    <!--class="am-icon-calendar"></span>-->
                    <!--</button>-->
                    <!--</span>-->
                    <!--</div>-->
                    <!--<input type="datetime-local" ng-value="schedule.firstDone*1000-->
                    <!--| date : 'yyyy-MM-ddTHH:mm:ss'" name="firstDone">-->
                    <input class="am-form-field" ui-date="{showTime:true}" ng-model="schedule.firstDone">
                </div>
            </div>
            <div class="am-g am-margin-top">
                <div class="am-u-sm-2 am-text-right">
                    上一次完成问卷时间
                </div>
                <div class="am-u-sm-10">
                    <!--<label type="text" class="am-input-sm" dateFormat ng-model="schedule.lastDone">{{schedule.lastDone*1000-->
                        <!--| date : 'yyyy-MM-dd HH:mm:ss'}}</label>-->
                    <input class="am-form-field" ui-date="{showTime:true}" ng-model="schedule.lastDone">

                </div>
            </div>
            <div class="am-margin">
                <!--<button type="submit" class="am-btn am-btn-primary am-btn-xs">Save</button>-->
                <button id="np-set" class="am-btn am-btn-primary">保存</button>
            </div>
        </form>
        <div class="am-margin">
            <button id="np-update" class="am-btn am-btn-primary" ng-click="check()">检测问卷状态</button>
        </div>
    </div>
    <!-- content end -->


    <footer>
        <hr>
    </footer>

    <!--[if lt IE 9]>
    <script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>
    <script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
    <script src="/static/assets/js/polyfill/rem.min.js"></script>
    <script src="/static/assets/js/polyfill/respond.min.js"></script>
    <script src="/static/assets/js/amazeui.legacy.js"></script>
    <![endif]-->

    <!--[if (gte IE 9)|!(IE)]><!-->
    <script src="/static/assets/js/jquery.min.js"></script>
    <script src="/static/assets/js/amazeui.min.js"></script>
    <!--<![endif]--></div>

<script src="/static/assets/js/app.js"></script>
<script src="/static/assets/js/angular.js"></script>
<script type="text/javascript" src="/static/assets/js/jquery-ui.min.js"></script>
<script type="text/javascript" src="/static/assets/js/date.js"></script>
<script type="text/javascript" src="/static/assets/js/jquery-ui-timepicker-addon.js"></script>
<script type="text/javascript">
    angular.module('App', ['ui.date']).controller('SurveyCtrl', function ($scope, $http) {
        $http.get("/rest/vadmin/survey/schedule").success(function (data) {
            $scope.schedule = data;
        }).error(function (data) {
        })
        $scope.save = function () {
            var progress = $.AMUI.progress;
            progress.set(0.4);
            firstDoneDate = $scope.schedule.firstDone
            lastDoneDate = $scope.schedule.lastDone
            var date = new Date(Date.parse(firstDoneDate));
            var date2 = new Date(Date.parse(lastDoneDate));
            var req = {
                method: 'POST',
                url: '/rest/vadmin/survey/schedule',
                headers: {
                    'Content-Type': 'application/json'
                },
                data: {'userPhone': $scope.schedule.userPhone, "firstDone": date.getTime() / 1000, "lastDone": date2.getTime() / 1000}
            }
            $.post(req.url, req.data).success(function (data) {
                progress.set(1)

            }).error(function (data) {
                alert('update fail')
                progress.set(1)
            });
        }
        $scope.check = function () {
            var progress = $.AMUI.progress;
            progress.set(0.4);
            $http.get("/rest/vadmin/survey/scheduleCheck").success(function (data) {
                $http.get("/rest/vadmin/survey/schedule").success(function (data) {
                    $scope.schedule = data;
                    progress.set(1)
                }).error(function (data) {
                    progress.set(1)
                })
            }).error(function (data) {
                progress.set(1)
            })
        }
    });
</script>
</body>
</html>
